/*
 * AdminControlPanel.fx
 * Author：Yu Min-ting
 * Created on 2009-7-13, 10:20:37
 */

package com.sjtu.fx.admin;

import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.paint.Color;
import javafx.scene.text.*;
import javafx.scene.effect.*;
import javafx.scene.input.MouseEvent;

import javafx.scene.effect.*;
import javafx.scene.layout.*;
import javafx.scene.shape.Rectangle;
import com.sjtu.fx.tools.Panel;




public class AdminControlPanel extends CustomNode {
    var panel:Panel;
    public var helloName:String;
//    public var adminLogOut:Boolean = false;
    var welcomeText = Text {
        id: "welcomeText"
        font: Font {size:12 name: "Verdana Bold"}
        fill: Color.rgb(11,51,60)
        content: bind helloName
    };

    var logOut : Button = Button {
        text: "Log Out"
        font: Font {size:11 name: "Verdana Bold"}
        action: function() {
            this.visible = false;
            this.parent.lookup("loginPanel").visible = true;
            this.parent.lookup("topBooks").visible = true;
            this.parent.lookup("recommendBooks").visible = true;
            this.parent.lookup("updateBook").visible = false;
            this.parent.lookup("changePaswd").visible = false;
        }
    }

    //admin control Panel
    var updateBooks : Text = Text{
        content: "Update New Books"
        fill: Color.rgb(11,51,60)
         font: Font{ size:13 name: "Verdana Bold"}
         onMouseEntered: function( e: MouseEvent ):Void {
                updateBooks.fill =  Color.BLUE;
                updateBooks.effect = Reflection {
                fraction: 0.75
                topOffset:-1.0
            }
             }
         onMouseExited: function(e:MouseEvent) {
               updateBooks.fill = Color.rgb(11,51,60);
               updateBooks.effect = null;
        }
        onMouseClicked: function( e: MouseEvent ):Void {
                this.parent.lookup("borrowBookCheck").visible = false;
                this.parent.lookup("topBooks").visible = false;
                this.parent.lookup("recommendBooks").visible = false;
                this.parent.lookup("searchResult").visible = false;
                this.parent.lookup("updateBook").visible = true;
        }
    }

    var userManage : Text = Text{
         content: "User Management"
        fill: Color.rgb(11,51,60)
         font: Font{ size:13 name: "Verdana Bold"}

         onMouseEntered: function( e: MouseEvent ):Void {
                userManage.fill =  Color.BLUE;
                userManage.effect = Reflection {
                fraction: 0.75
                topOffset:-1.0
            }
             }
         onMouseExited: function(e:MouseEvent) {
                userManage.fill = Color.rgb(11,51,60);
                userManage.effect = null;
        }
        onMouseClicked: function( e: MouseEvent ):Void {
                this.parent.lookup("userManagemet").visible = true;
                this.parent.lookup("topBooks").visible = false;
                this.parent.lookup("recommendBooks").visible = false;
        }
    }
    var bookManage : Text = Text{
         content: "Book Management"
        fill: Color.rgb(11,51,60)
         font: Font{ size:13 name: "Verdana Bold"}
         x: 145 y: 185

         onMouseEntered: function( e: MouseEvent ):Void {
                 bookManage.fill =  Color.BLUE;
                 bookManage.effect = Reflection {
                fraction: 0.75
                topOffset:-1.0
            }
             }
         onMouseExited: function(e:MouseEvent) {
                 bookManage.fill = Color.rgb(11,51,60);
                 bookManage.effect = null;
        }
        onMouseClicked: function( e: MouseEvent ):Void {
                this.parent.lookup("topBooks").visible = false;
                this.parent.lookup("recommendBooks").visible = false;
                this.parent.lookup("bookManagement").visible = true;
        }
    }

    var checkManage : Text = Text{
         content: "Check in/out Management"
        fill: Color.rgb(11,51,60)
         font: Font{ size:13 name: "Verdana Bold"}
         x: 145 y: 185

         onMouseEntered: function( e: MouseEvent ):Void {
                checkManage.fill =  Color.BLUE;
                checkManage.effect = Reflection {
                fraction: 0.75
                topOffset:-1.0
            }
             }
         onMouseExited: function(e:MouseEvent) {
                checkManage.fill = Color.rgb(11,51,60);
                checkManage.effect = null;
        }
        onMouseClicked: function( e: MouseEvent ):Void {
            this.parent.lookup("topBooks").visible = false;
            this.parent.lookup("recommendBooks").visible = false;
            this.parent.lookup("borrowBookCheck").visible = true;
        }
    }

    var purchaseManage : Text = Text{
         content: "Purchase Book Management"
        fill: Color.rgb(11,51,60)
         font: Font{ size:13 name: "Verdana Bold"}

         onMouseEntered: function( e: MouseEvent ):Void {
                purchaseManage.fill =  Color.BLUE;
                purchaseManage.effect = Reflection {
                fraction: 0.75
                topOffset:-1.0
            }
             }
         onMouseExited: function(e:MouseEvent) {
               purchaseManage.fill = Color.rgb(11,51,60);
               purchaseManage.effect = null;
        }
        onMouseClicked: function( e: MouseEvent ):Void {
                this.parent.lookup("topBooks").visible = false;
                this.parent.lookup("recommendBooks").visible = false;
                this.parent.lookup("bookPurchaseCheck").visible = true;
                this.parent.lookup("borrowBookCheck").visible = false;
        }
    }
    //user control panel
    var watingList : Text = Text{
        content: "My Wating List"
        fill: Color.rgb(11,51,60)
         font: Font{ size:13 name: "Verdana Bold"}
         visible:false
         onMouseEntered: function( e: MouseEvent ):Void {
                 watingList.fill =  Color.BLUE;
                 watingList.effect = Reflection {
                fraction: 0.75
                topOffset:-1.0
            }
             }
         onMouseExited: function(e:MouseEvent) {
                watingList.fill = Color.rgb(11,51,60);
                watingList.effect = null;
        }
        onMouseClicked: function( e: MouseEvent ):Void {

        }
    }

    var checkBooks : Text = Text{
         content: "Check in / Check out"
         fill: Color.rgb(11,51,60)
         font: Font{ size:13 name: "Verdana Bold"}
         visible:false
         onMouseEntered: function( e: MouseEvent ):Void {
                checkBooks.fill =  Color.BLUE;
                checkBooks.effect = Reflection {
                fraction: 0.75
                topOffset:-1.0
            }
             }
         onMouseExited: function(e:MouseEvent) {
                checkBooks.fill = Color.rgb(11,51,60);
                checkBooks.effect = null;
        }
        onMouseClicked: function( e: MouseEvent ):Void {
                this.parent.lookup("userBookPage").visible = true;
                this.parent.lookup("topBooks").visible = false;
                this.parent.lookup("recommendBooks").visible = false;
                this.parent.lookup("userBookPurchase").visible = false;
                this.parent.lookup("changePassWd").visible = false;
        }
    }
    var purchaseBooks : Text = Text{
         content: "Purchase Books"
         fill: Color.rgb(11,51,60)
         font: Font{ size:13 name: "Verdana Bold"}
         x: 145 y: 185
         visible:false
         onMouseEntered: function( e: MouseEvent ):Void {
                 purchaseBooks.fill =  Color.BLUE;
                 purchaseBooks.effect = Reflection {
                fraction: 0.75
                topOffset:-1.0
            }
             }
         onMouseExited: function(e:MouseEvent) {
                 purchaseBooks.fill = Color.rgb(11,51,60);
                 purchaseBooks.effect = null;
        }
        onMouseClicked: function( e: MouseEvent ):Void {
                this.parent.lookup("userBookPage").visible = false;
                this.parent.lookup("topBooks").visible = false;
                this.parent.lookup("recommendBooks").visible = false;
                this.parent.lookup("userBookPurchase").visible = true;
                this.parent.lookup("changePassWd").visible = false;
        }
    }
    var changePw : Text = Text{
         content: "Change Password"
         fill: Color.rgb(11,51,60)
         font: Font{ size:13 name: "Verdana Bold"}
         x: 145 y: 185
         visible:false
         onMouseEntered: function( e: MouseEvent ):Void {
                changePw.fill =  Color.BLUE;
                changePw.effect = Reflection {
                fraction: 0.75
                topOffset:-1.0
            }
         }
         onMouseExited: function(e:MouseEvent) {
                changePw.fill = Color.rgb(11,51,60);
                changePw.effect = null;
        }
        onMouseClicked: function( e: MouseEvent ):Void {
            this.parent.lookup("userBookPage").visible = false;
                this.parent.lookup("topBooks").visible = false;
                this.parent.lookup("recommendBooks").visible = false;
                this.parent.lookup("userBookPurchase").visible = false;
                this.parent.lookup("changePassWd").visible = true;
        }
    }

    var adminHome: Rectangle = Rectangle{
        width:100 height:22
        x:15 y:5
        fill:Color.rgb(200,225,230)
            onMouseEntered: function( e: MouseEvent ):Void {
                adminHome.fill = Color.rgb(152, 190, 198)
        }
            onMouseExited: function(e:MouseEvent) {
                adminHome.fill = Color.rgb(200,225,230)
        }
            onMouseClicked: function( e: MouseEvent ):Void {
                updateBooks.visible = true;
                userManage.visible = true;
                bookManage.visible = true;
                checkManage.visible = true;
                purchaseManage.visible = true;
                watingList.visible = false;
                checkBooks.visible = false;
                purchaseBooks.visible = false;
                changePw.visible = false; 
        }
    }
    var adminText = Text {
        font: Font {size:14 name: "Verdana Bold"}
        fill: Color.rgb(11,51,60)
        content: "Admin Home"
        x:15 y:20
    };
    var userHome: Rectangle = Rectangle{
        width:100 height:20
        x:119 y:5
        fill:Color.rgb(200,225,230)
            onMouseEntered: function( e: MouseEvent ):Void {
                userHome.fill = Color.rgb(152, 190, 198)
        }
            onMouseExited: function(e:MouseEvent) {
                userHome.fill = Color.rgb(200,225,230)
        }
            onMouseClicked: function( e: MouseEvent ):Void {
                updateBooks.visible = false;
                userManage.visible = false;
                bookManage.visible = false;
                checkManage.visible = false;
                purchaseManage.visible = false;
                watingList.visible = true;
                checkBooks.visible = true;
                purchaseBooks.visible = true;
                changePw.visible = true; 
        }
    }
     var userText = Text {
        font: Font {size:14 name: "Verdana Bold"}
        fill: Color.rgb(11,51,60)
        content: "My Library "
        x:125 y:20
    };
    override protected function create() : Node {
        Group{
            content:[
                 panel = Panel {
                    width:    290
                    height:   240
                    title:    "Admin Home| My Library"
                    translateX: 0
                    translateY: 0
                },
                adminHome, adminText,
                userHome, userText,
                HBox{
                    spacing: 20
                    translateX:80 translateY:50
                    content:[welcomeText,logOut]
                }

                //admin control panel
                 VBox{
                    spacing: 13
                    translateX:40 translateY: 80
                    content:[updateBooks, userManage, bookManage, checkManage,purchaseManage]
                },
                 //user control panel
                  VBox{
                    spacing: 20
                    translateX:40 translateY: 80
                    content:[watingList, checkBooks, purchaseBooks, changePw]
                },

            ]
        }
     }

}
